using System.Windows.Forms;

namespace Belmost4PDA.Logic
{
    public class StateRecord
    {
        protected readonly string textToShow = "Default";
        protected  int stateId = -1;
        protected bool enabled = false;
        protected readonly int startPanel = -1;

        /// <summary>
        /// Gets the text to show.
        /// </summary>
        /// <value>The text to show.</value>
        public string TextToShow
        {
            get { return textToShow; }
        }

        /// <summary>
        /// Gets the state id.
        /// </summary>
        /// <value>The state id.</value>
        public int StateId
        {
            get { return stateId; }
            set { stateId = value; }
        }

        /// <summary>
        /// Gets a value indicating whether this <see cref="StateRecord"/> is enabled.
        /// </summary>
        /// <value><c>true</c> if enabled; otherwise, <c>false</c>.</value>
        public bool Enabled
        {
            get { return startPanel == 0 ? true : enabled; }
        }

        /// <summary>
        /// Gets the start panel id.
        /// </summary>
        /// <value>The start panel.</value>
        public int StartPanel
        {
            get { return startPanel; }
        }

        /// <summary>
        /// Called when [global state change].
        /// </summary>
        virtual public void OnGlobalStateChange()
        {
            // get global
            GlobalStates global = GlobalStates.GetGlobalStates();
            if (global.BridgeWasChosen())
                enabled = true;
            else
                enabled = false;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="StateRecord"/> class.
        /// Add Globals OnChange listiner.
        /// </summary>
        /// <param name="StateId">The state id.</param>
        /// <param name="TextToShow">The text to show.</param>
        /// <param name="StartPanel">The start panel.</param>
        public StateRecord(int StateId, string TextToShow, int StartPanel)
        {
            stateId = StateId;
            textToShow = TextToShow;
            startPanel = StartPanel;
            // addin to globalslistening
            GlobalStates.GetGlobalStates().OnChange += OnGlobalStateChange;
        }
        public StateRecord():this(-1, "Default", -1)
        {
        }

        /// <summary>
        /// Quits the state.
        /// </summary>
        virtual public void QuitState()
        {
            StateDispatcher disp = StateDispatcher.GetDispatcher();
            disp.QuitFromState();
        }

        /// <summary>
        /// Runs the state.
        /// </summary>
        virtual public void RunState(Form form)
        {
            // empty run - just Quit
            QuitState();
        }
    }
}